// /rule/addRuleInfo.do
var _url_ = '../print/addShopPrintInfo.do';
var _url_edit = '../print/updateShopPrintInfo.do';
var _url_list = '../print/getShopPrintList';
var _url_id = '../print/getShopPrintById';
var _map = {};
///首页
var _pageNum = 1;
var _type ;
var spid="";
  $(function(){
	   spid = getCookie("shop_id");
	  _type = getUrlParam("type");
	  console.log(_type);
	  if(_type === "add"){
		 // getTypeListAdd();
		  _showData = {};
		  $("#shopId").val(spid);
	  }else if(_type === "edit"){
		  showEditData();
		  _url_ = _url_edit;
	  }else{
//		  getTypeList();
//		  getProfitsInfo();
		 getList();
	  }
  })
$(function(){
	  $("body").on("click",".mypage span",function(){
		  _pageNum = $(this).attr("data-status");
		  getList();
	  })
	  $(".search-btn").click(function(){
			 var tabletitle =  $("#table-title").val();
			 _pageNum = 1;
			 _map["title"] = tabletitle;
			 getList();
		  });
	  $("body").on("click",".left-type li",function(){
			 var tt = $(this).text();
			 $(this).addClass('lt-li-active').siblings().removeClass('lt-li-active');
			 _map['goodsTypeId'] = $(this).attr('data-status');
			 getList();
	  });
});
  function getList(){
	  _map['shopId'] = spid;
	  _map['pageNum'] = _pageNum;
	  _ajax_get(_url_list,_map,function(res){
		  console.log(res);
		  console.log(res.returnObject);
		  if(!res.returnObject||res.returnObject.length<=0 ){
			  $(".layui-table tbody").html("");
			  $(".no-more-data").show();
			  $(".mypage").hide();
			  return;
		  }else{
			  $(".mypage").show();
			  $(".no-more-data").hide();
		  }
		  var html = "";
		  var stat = "" , statHtml = "";
		  showPageInfo(res.returnObject);
		  $(".x-right").text("共有数据："+res.returnObject.total +" 条");
		  var html,stat,statStr,typeStr,sendTypeStr;
		  $.each(res.returnObject.list,function(i,v,arr){
			  console.log(v);
			  if(v.type == 1){
				  typeStr = "蓝牙打印机";
			  }else if(v.type == 2){
				  typeStr = "wifi打印机";
			  }else{
				  typeStr = "USB打印机";
			  }
			  html+=' <tr><td>'
 	             +(i+1)+'</td>                                                                                                             '
 	             +' <td>'+v.title
 	             +'</td>                                                                                           '
// 	             +' <td align="center"><a target="_blank" href="'+v.adUrl+'"><img  src="'+v.adPic+'" height=50 widht=50 ></a></td>                                                                                                      '
// 	             +' <td>'+v.adUrl+'</td>                                                                                                      '
 	             +' <td>'+(v.location==1?"前台":"后厨")+'</td>                                                                                                      '
 	             +' <td >'+typeStr+'</td>'
 	             +' <td>'+(v.status==1?"开启":"关闭")+'</td>                                                                                                      '
 	             +' <td class="td-manage">    '
 	             +'   <a title="编辑"  onclick="x_admin_show(\'修改打印机 - '+v.title+'\',\'./shops~shop-print-add.html?type=edit&id='+v.id+'\',451,580)" href="javascript:;">                       '
	             +'     <i class="iconfont">修改</i>                                                                                 '
	             +'   </a>'
 	             + '<a title="删除" onclick="member_del(this,\''+v.id+'\')" href="javascript:;">                                         '
 	             +'     <i class="iconfont icon-delete x-red"></i>                                                                                 '
 	             +'   </a>  </td> </tr>';
		  })
		  $(".layui-table tbody").html(html);
	  })
  }
  
  /*用户-删除*/
  function member_del(obj,_id){
      layer.confirm('确认要删除吗？',function(index){
          //发异步删除数据
    	  _ajax_post_token(_url_edit,{status:0,id:_id},function(res){
    	      	console.log(res);
    	      	if(res.resultCode == 1000){
    	      		getList();
    	      	  layer.msg('删除成功!',{icon:6,time:2000});
    	      	}else{
    	      		layer.msg('删除失败!',{icon:5,time:2000});
    	      	}
    	      });
      });
  }
  function showQr(_title,_url){
	  layer.open({ title: _title,content:'<img width=250 height=250 src="'+_url+'" />' });
  }
  function showEditData(){
	  _url_ = _url_edit;
	  var _id = getUrlParam("id");
	  $("#paramKey").val(_id);
	  console.log(_id);
	  _ajax_post_token(_url_id,{id:_id},function(res){
		  console.log(res);
		  _showData = res.returnObject;
	  });
  }    
  function updateInfo(data){
	  //发异步，把数据提交给后台
	 console.log(_url_);
	 disAddBtn();
	 data['shopId'] = spid;
      _ajax_post_token(_url_,data,function(res){
      	console.log(res);
      	if(res.resultCode == 1000){
      	  parent.getList();
      	  parent.layer.msg('操作成功!',{icon:6,time:2000});
      	  x_admin_close();
          // 获得frame索引
      	}else{
      		layer.msg('操作失败!',{icon:5,time:2000});
      	}
      	cecDisAddBtn();
      });
  }
      
  
  function delAll (argument) {
      var data = tableCheck.getData();
      if(!data || data.length==0){
    	  layer.msg('至少选择一条数据',{icon:5,time:2000});
    	  return;
      }
      console.log(data.join(","));
      layer.confirm('确认要删除已选择的数据吗？',function(index){
          //捉到所有被选中的，发异步进行删除
    	  _ajax_post_token(_url_edit,{ids:data.join(",")},function(res){
    	      	console.log(res);
    	      	if(res.resultCode == 1000){
    	      	  getList();
    	      	  layer.msg('操作成功!',{icon:6,time:2000});
    	          // 获得frame索引
    	      	}else{
    	      		layer.msg('操作失败!',{icon:5,time:2000});
    	      	}
    	      });
      });
    }      
       
  function test(_d){
	  console.log(_d);
  }
      
//添加 和 修改窗口     